/*
* pps_bom
*/
package com.pitop.assembly.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.assembly.entity.AssemblyCategory;
import com.pitop.assembly.entity.AssemblyCategoryState;
import com.pitop.assembly.service.AssemblyCategorySV;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.tools.StringTools;
import com.pitop.core.tools.redis.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 组件类型 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/assemblyCategory")
@Slf4j
@Api(value = "组件类型控制器", description = "组件类型控制器")
public class AssemblyCategoryCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private AssemblyCategorySV assemblyCategorySV;

    /**
     * 查询AssemblyCategory一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyCategory一个详情信息", notes = "查询AssemblyCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public AssemblyCategory load(Long id, String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        AssemblyCategory assemblyCategory = assemblyCategorySV.load(id, code);
        log.info(JSON.toJSONString(assemblyCategory));
        return assemblyCategory;
    }

    /**
     * 查询AssemblyCategory一个详情信息，(将查询关联数据)
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyCategory一个详情信息", notes = "查询AssemblyCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/get")
    @ResponseBody
    public AssemblyCategory get(Long id, String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        AssemblyCategory assemblyCategory = assemblyCategorySV.get(id, code);
        log.info(JSON.toJSONString(assemblyCategory));
        return assemblyCategory;
    }

    /**
     * 根据条件id查询AssemblyCategory一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyCategory一个详情信息", notes = "查询AssemblyCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public AssemblyCategory loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        AssemblyCategory assemblyCategory = assemblyCategorySV.loadById(id);
        log.info(JSON.toJSONString(assemblyCategory));
        return assemblyCategory;
    }

    /**
     * 根据条件code查询AssemblyCategory一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyCategory一个详情信息", notes = "查询AssemblyCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public AssemblyCategory loadByCode(@PathVariable String code) {
        if (code == null) {
            return null;
        }
        AssemblyCategory assemblyCategory = assemblyCategorySV.loadByCode(code);
        log.info(JSON.toJSONString(assemblyCategory));
        return assemblyCategory;
    }

    /**
     * 根据条件code查询AssemblyCategory一个详情信息
     *
     * @param name 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyCategory一个详情信息", notes = "查询AssemblyCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/name/{name}")
    @ResponseBody
    public AssemblyCategory loadByname(@PathVariable String name) {
        if (StringTools.isEmpty(name)) {
            return null;
        }
        AssemblyCategory assemblyCategory = assemblyCategorySV.loadByName(name);
        log.info(JSON.toJSONString(assemblyCategory));
        return assemblyCategory;
    }

    /**
     * 根据条件id查询AssemblyCategory一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyCategory一个详情信息", notes = "查询AssemblyCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/get/id/{id}")
    @ResponseBody
    public AssemblyCategory getById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        AssemblyCategory assemblyCategory = assemblyCategorySV.getById(id);
        log.info(JSON.toJSONString(assemblyCategory));
        return assemblyCategory;
    }

    /**
     * 根据条件code查询AssemblyCategory一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyCategory一个详情信息", notes = "查询AssemblyCategory一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/get/code/{code}")
    @ResponseBody
    public AssemblyCategory getByCode(@PathVariable String code) {
        if (code == null) {
            return null;
        }
        AssemblyCategory assemblyCategory = assemblyCategorySV.getByCode(code);
        log.info(JSON.toJSONString(assemblyCategory));
        return assemblyCategory;
    }

    /**
     * 查询AssemblyCategory信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询AssemblyCategory信息集合", notes = "查询AssemblyCategory信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isShowAll", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<AssemblyCategory> list(@RequestBody @ApiIgnore AssemblyCategory assemblyCategory, String isShowAll, Integer curPage, Integer pageSize) {
        Page<AssemblyCategory> page = new Page<AssemblyCategory>(pageSize, curPage);
        List<AssemblyCategory> assemblyCategorys = assemblyCategorySV.list(assemblyCategory, isShowAll, page.genRowStart(), page.getPageSize());
        log.info(JSON.toJSONString(page));
        return assemblyCategorys;
    }

    /**
     * 查询AssemblyCategory信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询AssemblyCategory信息集合", notes = "查询AssemblyCategory信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<AssemblyCategory> listByPk(Long id, String code, Integer curPage, Integer pageSize) {
        Page<AssemblyCategory> page = new Page<AssemblyCategory>(pageSize, curPage);
        List<AssemblyCategory> assemblyCategorys = assemblyCategorySV.list(id, code, page.genRowStart(), page.getPageSize());
        int total = assemblyCategorySV.count(id, code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return assemblyCategorys;
    }

    /**
     * 统计AssemblyCategory信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计AssemblyCategory信息数量根据主键", notes = " 统计AssemblyCategory信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String code) {
        return assemblyCategorySV.count(id, code);
    }

    /**
     * 统计AssemblyCategory信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计AssemblyCategory信息数量", notes = "统计AssemblyCategory信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "preCode", value = "上级编码", paramType = "query"),
            @ApiImplicitParam(name = "level", value = "上级级别", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "类型名", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "描述", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态[启用 enable,禁用 disable]", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody AssemblyCategory assemblyCategory) {
        return assemblyCategorySV.count(assemblyCategory);
    }

    /**
     * 创建AssemblyCategory
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建AssemblyCategory", notes = "创建AssemblyCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preCode", value = "上级编码", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "类型名", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "描述", paramType = "query"),
    })
    @PostMapping("/build")
    @ResponseBody
    public AssemblyCategory build(@RequestBody @ApiIgnore AssemblyCategory assemblyCategory) {
        assemblyCategorySV.save(assemblyCategory);
        return assemblyCategory;
    }

    /**
     * 修改AssemblyCategory
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改AssemblyCategory", notes = "修改AssemblyCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "preCode", value = "上级编码", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "类型名", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "描述", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态[启用 enable,禁用 disable]", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public AssemblyCategory modify(@RequestBody @ApiIgnore AssemblyCategory assemblyCategory) {
        assemblyCategorySV.modify(assemblyCategory);
        return assemblyCategory;
    }

    /**
     * 修改状态
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改AssemblyCategory", notes = "修改AssemblyCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query", required = true),
            @ApiImplicitParam(name = "state", value = "状态[启用 Enable,禁用 Disable]", paramType = "query", required = true)
    })
    @PutMapping("/updateState")
    @ResponseBody
    public BeanRet updateState(String code, String state) {
        assemblyCategorySV.updateByCode(code, AssemblyCategoryState.getEnum(state));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success);
    }

    /**
     * 删除AssemblyCategory
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除AssemblyCategory", notes = "删除AssemblyCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String code) {
        assemblyCategorySV.delete(id, code);
        return BeanRet.create(true, "删除AssemblyCategory成功");
    }

}
